﻿using System;


using System.Text;
using IAM.Interface.Model.Interface;
using System.Xml;
using System.Reflection;

namespace IAM.Interface.Model
{

    /// <summary>
    /// 本节包含权限模型中权限区定义列表
    /// 包含1个或多个权限区的描述
    /// </summary>
    public class ACSections : AbstractConvertObject,IConvertXml
    {
        #region 构造函数
        /// <summary>
        /// 构造函数
        /// </summary>
        public ACSections()
        {
            _acsections = new System.Collections.ArrayList();
        }
        #endregion
        #region 属性
        private System.Collections.ArrayList _acsections;
        /// <summary>
        /// 权限模型中权限区定义列表
        /// 包含1个或多个权限区的描述 ACSection集合
        /// </summary>
        public System.Collections.ArrayList Items
        {
            set
            {
                _acsections = value;
            }
            get
            {
                return _acsections;
            }
        }
        /// <summary>
        /// 权限模型中权限区定义列表数量
        /// </summary>
        public int Count
        {
            get
            {
                return Items.Count;
            }
        }
        #endregion
        #region IConvertXml

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append("<ACSections");
                _xml.Append(" Count=\"" + this.Count + "\"");
                _xml.Append(" >");
                foreach (System.Object section in Items)
                {
                    _xml.Append(((ACSection)section).XML);
                }
                return _xml.ToString();
            }


        }

        public string XMLFinis
        {
            get
            {
                return "</ACSections>";
            }
        }
        public string XML
        {
            get
            {
                return XMLBoday + XMLFinis;
            }
        }
        #endregion
        #region AbstractConvertObject
        public override object ConvertToObject()
        {
            foreach (XmlNode xmlnode in this.CurrentXmlNode.ChildNodes)
            {
                ACSection acsection = new ACSection();
                acsection.CurrentXmlNode = xmlnode;
                acsection = (ACSection)acsection.ConvertToObject();
                this.Items.Add(acsection);
            }
            return this;
        }
        #endregion
        #region 重写Equals
        /// <summary>
        /// 确定指定的 ACSections 对象是否等效于当前 ACSections
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            ACSections acs = null;
            try
            {
                acs = (ACSections)obj;
            }
            catch
            {
                return false;
            }
            bool result = true;
            if (this.Items.Count != acs.Items.Count)
            {
                result = false;
            }
            else
            {
                foreach (object oneofsource in this.Items)
                {
                    ACSection acssource = (ACSection)oneofsource;
                    result = false;

                    foreach (object oneofobj in acs.Items)
                    {
                        ACSection acsobj = (ACSection)oneofobj;
                        if(acssource.Equals(acsobj))
                        {
                            result = true;
                            break;
                        }
                    }
                    if (result == false)
                    {
                        break;
                    }
                }
            }

            return result;
        }

        #endregion
        #region 重写GetHashCode
        /// <summary>
        /// 哈希函数
        /// </summary>
        /// <returns></returns>
        public override int GetHashCode()
        {
            int result = 1;
            PropertyInfo[] pi = this.GetType().GetProperties();
            foreach (PropertyInfo onofpi in pi)
            {
                result = result + onofpi.GetHashCode();
            }
            return result;
        }
        #endregion
    }
}
